package com.example.demo01.Controller.webController;

import com.alibaba.fastjson.JSON;
import com.example.demo01.Service.webService.HealthInfoRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthInfoRecordController {

    @Autowired
    private HealthInfoRecordService healthInfoRecordService;

    /**
     * 获取所有健康信息记录
     * */
    @RequestMapping("/healthrecord/GET/allrecords")
    public String getAllHealthRecords(){
        return JSON.toJSONString(healthInfoRecordService.getAllHealthRecords());
    }

    /**
     * 根据身份证号获取健康信息记录
     * */
    @RequestMapping("/healthrecord/GET/recordsbyidnum")
    public String getHealthRecordByIdNum(
            @RequestParam(value = "idnum",required = false,defaultValue = "") String idNum,
            @RequestParam(value = "limitcount",required = false,defaultValue = "5") int limitCount){
        return JSON.toJSONString(healthInfoRecordService.getHealthRecordByIdNum(idNum,limitCount));
    }

    /**
     * 根据身份证号获取单条——统计性健康信息记录
     * */
    @RequestMapping("/healthrecord/GET/byidnum")
    public String getHealthRecordByIdNum(
            @RequestParam("idnum") String idnum
    )
    {
        return JSON.toJSONString(healthInfoRecordService.getHealthRecordByIdNum(idnum));
    }
}
